<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2016/5/29
  Time: 9:34
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <link rel="stylesheet" href="/wechat/home/praise.css">
    <jsp:include page="../public/head.jsp" flush="true" />
</head>
<body>
<jsp:include page="../public/header.jsp" flush="true" />
<div class="my_praise">
<section >
    <div id="data"></div>
    <%--<c:forEach items="${comments}" var="item">--%>
        <%--&lt;%&ndash;<div>${item.content}</div>&ndash;%&gt;--%>
            <%--<!-- 评价内容 -->--%>
            <%--<div class="cont">--%>
                <%--<div class="cont_in">--%>
                    <%--<div class="left" style="background: url(${item.userPhoto}) 0 0 no-repeat; background-size:100% 100%;" ></div>--%>
                    <%--<div class="center"><span class="s1">${item.nickName}</span><span class="s2">${item.addTime}</span></div>--%>
                    <%--<div class="right">${item.tasteScore}分</div>--%>
                <%--</div>--%>
                <%--<div class="txt">${item.content}</div>--%>
                <%--<div class="ocupie"></div>--%>
            <%--</div>--%>
            <%--<!--/cont-->--%>
       <%-->--%>
    <%--</c:forEach> --%>
    <div class="ps" id="pullRefresh" hidden>正在加载</div>
</section>
</div>
<script>
    var isLast = false;
    var index = 0;
    var size = 10;

    $(function () {
        update();
    });

    $(window).scroll(function() {
        var scrollTop = $(this).scrollTop();
        var scrollHeight = $(document).height();
        var windowHeight = $(this).height();
        if(scrollTop + windowHeight == scrollHeight){
            if (!isLast)
                update();
        }
    });

        function update() {
        $("#pullRefresh").toggle();

        $.post("/mobile/product?action=comment",{id:${product.id},begin:index,end:size},function(data){
            index = index+size;
            if (!data.success){
                alert(data.msg);
            }else {
                if (data.data.length > 0) {
                    $("#pullRefresh").toggle();
                    var html = "";
                    $.each(data.data, function (i, item) {
                        html +=
                        '<div class="cont">'+
                        '       <div class="cont_in">'+
                        '       <div class="left" style="background: url('+item.userPhoto+') 0 0 no-repeat; background-size:100% 100%;" ></div>'+
                        '       <div class="center"><span class="s1">'+item.nickName+'</span><span class="s2">'+item.addTime+'</span></div>'+
                        '       <div class="right">'+item.ave+'分</div>'+
                        '       </div>'+
                        '       <div class="txt">'+item.content+'</div>'+
                        '       <div class="ocupie"></div>'+
                        '       </div>';
                    });
                    $("#data").append(html);
                }else{
                    isLast = true;
                    $("#pullRefresh").text("已经加载全部");
                }
            }
        },"json");
    }
</script>
</body>
</html>
